// Kony


#include "UI/WidgetController/BaseWidgetController.h"

#include "AbilitySystem/BaseAbilitySystemComponent.h"
#include "AbilitySystem/BaseAttributeSet.h"
#include "AbilitySystem/Data/AbilityInfo.h"
#include "Player/BasePlayerController.h"
#include "Player/BasePlayerState.h"

void UBaseWidgetController::SetWidgetControllerParams(const FWidgetControllerParams& WCParams)
{
	PlayerController = WCParams.PlayerController;
	PlayerState = WCParams.PlayerState;
	AbilitySystemComponent = WCParams.AbilitySystemComponent;
	AttributeSet = WCParams.AttributeSet;
}

void UBaseWidgetController::BroadcastInitializeValues()
{
	
}

void UBaseWidgetController::BindCallbacksToDependencies()
{
}
//初始化启动能力技能委托绑定
void UBaseWidgetController::BroadcastAbilityInfo()
{
	//判断如果能力为被赋予，则返回
	if (!GetBaseASC()->bStartupAbilitiesGiven) return;

	//创建广播回调函数
	FForEachAbility BroadcastDelegate;
	BroadcastDelegate.BindLambda([this](const FGameplayAbilitySpec& AbilitySpec)
	{
		//通过能力规格获取到 所有包含能力的标签，并通过能力标签获取对应的能力信息
		FBaseAbilityInfo Info = AbilityInfo->FindAbilityInfoForTag(BaseAbilitySystemComponent->GetAbilityTagFromSpec(AbilitySpec));
		//获取并设置输入按键标签
		Info.InputTag = BaseAbilitySystemComponent->GetInputTagFromSpec(AbilitySpec);
		//获取并设置能力状态标签
		Info.StatusTag = BaseAbilitySystemComponent->GetStatusFromSpec(AbilitySpec);
		//广播到技能小部件 到覆盖层界面
		AbilityInfoDelegate.Broadcast(Info);
	});
	//绑定循环已激活能力委托回调函数
	GetBaseASC()->ForEachAbility(BroadcastDelegate);
}

//获取Base玩家控制器
ABasePlayerController* UBaseWidgetController::GetBasePC()
{
	//如果变量为空，则强制转换系统类为Base类型
	if (BasePlayerController == nullptr)
	{
		BasePlayerController = Cast<ABasePlayerController>(PlayerController);
	}
	return BasePlayerController;
}
//获取Base玩家属性状态
ABasePlayerState* UBaseWidgetController::GetBasePS()
{
	if (BasePlayerState == nullptr)
	{
		BasePlayerState = Cast<ABasePlayerState>(PlayerState);
	}
	return BasePlayerState;
}
//获取Base玩家能力系统组件
UBaseAbilitySystemComponent* UBaseWidgetController::GetBaseASC()
{
	if (BaseAbilitySystemComponent == nullptr)
	{
		BaseAbilitySystemComponent = Cast<UBaseAbilitySystemComponent>(AbilitySystemComponent);
	}
	return BaseAbilitySystemComponent;
}
//获取Base玩家属性集
UBaseAttributeSet* UBaseWidgetController::GetBaseAS()
{
	if (BaseAttributeSet == nullptr)
	{
		BaseAttributeSet = Cast<UBaseAttributeSet>(AttributeSet);
	}
	return BaseAttributeSet;
}

 
